/**
 * Created by lili on 2017/7/11.
 */
var CPU = function(){};

CPU.prototype = {
    freeze:function () {
        console.log("Cpu Freeze");
    },
    jump:function(position){
        console.log('CPU: jump to ' + position);
    },
    execute:function(){
        console.log('CPU: execute');
    }
};


var Memory = function () {};
Memory.prototype = {
    load: function (position, data) {
        console.log('Memory: load "' + data + '" at ' + position);
    }
};

var HardDrive = function () {};
HardDrive.prototype = {
    read: function (lba, size) {
        console.log('HardDrive: read sector ' + lba + '(' + size + ' bytes)');
        return 'hdd data';
    }
};

//Facade Object   好久不看Js，快忘完了.....
var Computer = function(){
    var cpu,memory,hardDrive;
    cpu = new CPU();
    memory = new Memory();
    hardDrive = new HardDrive();

    var constant = function(name){
        var constants = {
            BOOT_ADDRESS: 0,
            BOOT_SECTOR: 0,
            SECTOR_SIZE: 512
        };
        return constants[name];
    };

    this.startComputer = function(){
        cpu.freeze();
        memory.load(constant('BOOT_ADDRESS'), hardDrive.read(constant('BOOT_SECTOR'), constant('SECTOR_SIZE')));
        cpu.jump(constant('BOOT_ADDRESS'));
        cpu.execute();
    }
}

var facade = new Computer();
facade.startComputer();

